const express = require('express')
const router = express.Router();
const db = require('../../utils/db')
router.get('/xjh/manage/Product', (req, res) => {
  const sqlAa = `SELECT pack_rank,menu_name,menu_num,pack_start_time,
    pack_end_time,pack_state,user_name,pack_publish_time FROM package_list 
    JOIN menu_file 
    ON package_list.pack_num=menu_file.menu_id
    JOIN USER ON package_list.pack_founder=user.user_id;`;
  db(sqlAa, null, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: '失败' })
    } else {
      res.send({ error: 0, msg: '数据成功', data: data })
    }
  })
});
router.get('/xjh/manage/Product/pro', (req, res) => {
  const sqla = `UPDATE package_list SET pack_state ='终止促销' WHERE pack_rank=${req.query.pack_rank}`
  db(sqla, null, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: "暂停失败" })
    } else {
      res.send({ error: 0, msg: '暂停成功', data: data })
    }
  })
})
router.get('/xjh/manage/Product/food', (req, res) => {
  const sqlb = `SELECT menu_id,menu_name,menu_num FROM menu_file;`
  db(sqlb, null, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: "菜品信息查询失败" })
    } else {
      res.send({ error: 0, msg: '菜品信息查询成功', data: data })
    }
  })
})
router.get('/line', (req, res) => {
  const sqlc = `SELECT  pack_rank FROM package_list ;`
  db(sqlc, null, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: "菜品信息查询失败" })
    } else {
      res.send({ error: 0, msg: '菜品信息查询成功', data: data })
    }
  })
})
router.get('/sendTwo', (req, res) => {
  const sqld = `INSERT INTO package_list VALUES(NULL,${req.query.park_num},'${req.query.pack_start_time}','${req.query.pack_end_time}','${req.query.pack_state}',${req.query.pack_founder},'${req.query.pack_publish_time}','${req.query.pack_rank}');`
  db(sqld, null, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: "菜品添加失败" })
    } else {
      res.send({ error: 0, msg: '菜品添加成功', data: data })
    }
  })
})

module.exports = router